/**
 * Created by charsen on 16/6/7.
 */
directives.directive('priceMonitorDataAnalyse', ["$rootScope", "tools", "$timeout", function ($rootScope, tools, $timeout) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attr) {
            $rootScope.$on('PRICE_MONITOR_DATA_ANALYSE_EV', function () {
                $(element).modal('show');
                cityAnalyse();
                creditAnalyse();
                timeAnalyse();
                methodAnalyse();
            });
            scope.close = function () {
                $(element).modal('hide');
            }

            function cityAnalyse() {
                $(element).find('.cityAnalyse').highcharts({
                    chart: {
                        plotBackgroundColor: null,
                        plotBorderWidth: null,
                        plotShadow: false
                    },
                    title: {
                        text: '低价地区占比'
                    },
                    tooltip: {
                        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                    },
                    plotOptions: {
                        pie: {
                            allowPointSelect: true,
                            cursor: 'pointer',
                            dataLabels: {
                                enabled: true,
                                color: '#000000',
                                connectorColor: '#000000',
                                format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                            }
                        }
                    },
                    series: [{
                        type: 'pie',
                        name: '低价地区占比',
                        data: [
                            ['合肥', 45.0],
                            ['石家庄', 26.8],
                            ['桐城', 8.5],
                            ['宁波', 6.2],
                            ['北京', 0.7]
                        ]
                    }]
                });
            }

            function creditAnalyse() {
                $(element).find('.creditAnalyse').highcharts({
                    chart: {
                        plotBackgroundColor: null,
                        plotBorderWidth: null,
                        plotShadow: false
                    },
                    title: {
                        text: '低价地区占比'
                    },
                    tooltip: {
                        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                    },
                    plotOptions: {
                        pie: {
                            allowPointSelect: true,
                            cursor: 'pointer',
                            dataLabels: {
                                enabled: true,
                                color: '#000000',
                                connectorColor: '#000000',
                                format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                            }
                        }
                    },
                    series: [{
                        type: 'pie',
                        name: '低价信誉占比',
                        data: [
                            ['2星', 45.0],
                            ['3星', 10.8],
                            ['1钻', 2.5],
                            ['2钻', 56.2],
                            ['3钻', 15.7]
                        ]
                    }]
                });
            }

            function timeAnalyse() {
                $(element).find('.timeAnalyse').highcharts({
                    chart: {
                        plotBackgroundColor: null,
                        plotBorderWidth: null,
                        plotShadow: false
                    },
                    title: {
                        text: '低价时间段占比'
                    },
                    tooltip: {
                        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                    },
                    plotOptions: {
                        pie: {
                            allowPointSelect: true,
                            cursor: 'pointer',
                            dataLabels: {
                                enabled: true,
                                color: '#000000',
                                connectorColor: '#000000',
                                format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                            }
                        }
                    },
                    series: [{
                        type: 'pie',
                        name: '低价信誉占比',
                        data: [
                            ['09:00-11:00', 23.0],
                            ['13:00-14:00', 15.8],
                            ['15:30-16:30', 12.5],
                            ['20:00-21:00', 50.2],
                            ['23:00-23:30', 30.7]
                        ]
                    }]
                });
            }

            function methodAnalyse() {
                $(element).find('.methodAnalyse').highcharts({
                    chart: {
                        plotBackgroundColor: null,
                        plotBorderWidth: null,
                        plotShadow: false
                    },
                    title: {
                        text: '低价方式对比'
                    },
                    tooltip: {
                        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                    },
                    plotOptions: {
                        pie: {
                            allowPointSelect: true,
                            cursor: 'pointer',
                            dataLabels: {
                                enabled: true,
                                color: '#000000',
                                connectorColor: '#000000',
                                format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                            }
                        }
                    },
                    series: [{
                        type: 'pie',
                        name: '低价信誉占比',
                        data: [
                            ['价格', 23.0],
                            ['买就送', 15.8],
                            ['满减', 12.5]
                        ]
                    }]
                });
            }
        },
        templateUrl: "/trend-new-BI/app/components/priceMonitor/priceMonitorDataAnalyse/priceMonitorDataAnalyseView.html"
    }
}]);